#include<iostream>
#include<fstream>
//#include<sstream>
//#include<cstdlib>
//#include<list>
//#include<string.h>
#include<map>

typedef short unsigned int suint;
using namespace std;

class univariate_settings_t{
public:
  string phenofile;
  string maskfile;
  string annotationfile;
  string type;
  string regression;
  char geno_format;
};


class Univariate:public Analyzer{
private:
  univariate_settings_t * settings;
  const char * ANNOTATION_FILE;
  const char * MASKFILE;
  const char * phenofile;
  
  bool logistic;
  bool marginal;
  char typed_imputed;

  bool * mask;
  bool printAnnot;
  uint persons;
  uint covariates;
  uint veclen;
  ofstream ofs_snpstats;
  
  struct snpinfo{
    short int chr ;
    int pos ;
    char other ;
    char ref ;
    float rsq ;
  };
  
  map<string,snpinfo> snpinfo_map;
  
  void getDouble(char t_i,const string & str, double * output);
  void loadmask();
  double HWEpvalue(uint * cellcounts,double maf);
  void printtyped(double * geno,double & callrate,double & maf, double & hwe, double & exp_het, double & obs_het);
  void printimputed(double * geno, double & maf1);
  inline snpinfo fetch(map<string,snpinfo> & data,const string key){
    map<string,snpinfo>::iterator it;
    it = data.find(key);
    if (it==data.end()){
      snpinfo b;
      return b;
    }
    return it->second;
  }
  
  void loadAnnotation();
  void loadPheno(double * phenovec, double * designmat,bool * defined,uint & rank);
public:
  void init(const ptree & pt);
  Univariate();
  ~Univariate();
  void run();
};
